<?php
session_start();
error_reporting(E_ALL && ~ E_NOTICE);
include '../../db/dbConnect.php';
include '../function/mysql.php';
include '../function/pagging.php';
include '../function/helper.php';
?>
<style type="text/css">
.question{
    color: #025AF2;
    font-size: 16px;
    font-weight: bold;
    border-radius: 3px 3px 0px 0px;
    padding: 1%;
    background: none repeat scroll 0% 0% #D1F38F;
    margin: 5px auto;
}
.answer{
    font-weight: 100;
    font-size: 14px;
    color: #000;
    background: none repeat scroll 0% 0% #FFF;
    width: 94%;
    border-radius: 3px;
    padding: 0px 3%;
    line-height: 1.7;
}
</style>
<script type="text/javascript">
	$("a.re_ans").bind('click',function(){
		var id=$(this).attr("id");
		var $this=$(this);
		
		$.ajax({
			type:'get',
			url:'web/member/list_ans.php',
			data:'idquest='+id+'&kind=re_ans',
			success:function(result){
				//alert(result);
				$('.answer').hide("fast");
				$this.siblings('div.new_ans').empty().hide().append(result).show('slow');
				
				$this.hide();
			}
		});
		
		return false;
	});
	$("a.add_more").bind('click', function(){
		var hrf=$(this).attr('href');
		//alert(hrf);
		$("div.pLeft").hide().load(hrf).fadeIn(1000);
		return false;
	});
	var $iduser=$(".question").attr('user');
	
	$('a.pag_nav').click(function(){
		var $href=$(this).attr('href');
		//alert($href);
		$("div.pLeft").load($href);
		return false;
	});
</script>
<?php
if($_SERVER['REQUEST_METHOD']=="GET" && ($_GET["user_profile"] || $_GET["id"]  )){
    $user=($_GET["user_profile"]!=0)?$_GET["user_profile"]:$_GET["id"] ;

    $host=0;
    if($user==$_SESSION['LoginData']['iduser'])$host=1;
}else {
    //unset($user);
    $host=1;
    $user=$_SESSION['LoginData']['iduser'];
}
if($user==$_SESSION['LoginData']['iduser'])$host=1;
?>
<div id="q_profile">
    <div class="w100p hQ">
        <h3 class="w40p left">Danh sách câu hỏi bạn đã trả lời</h3>
        <?php if($host){?><a href="web/member/new_question.php" class="add_more right">Câu hỏi khác </a><?php } ?>
    </div>


<?php
	
	$p=new Pager();
    $p->setId($user);
    $p->setLink();
	$p->setLimit(5);
	$p->findStart($p->getLimit());

	$result=select_quest_user($user,0,0,0);
	echo mysql_error();
	$count=0;
	$count=mysql_num_rows($result);
	$p->findPages($count, $p->getLimit());
	
	$result=select_quest_user($user,0,$p->getStart(),$p->getLimit());
	echo mysql_error();
	$i=1;
	while($row=mysql_fetch_array($result)){
?>

<div class="question" user="<?php echo $user;?>"><?php echo '<strong>'.$i++.'_  </strong>'.$row['ques'];?>
<div class="wrap_ans">
	<div class="answer"><?php echo $row['ans'];?></div>
    <div class="new_ans"></div>
    <?php if($host==1){?>
	<a href="#" id="<?php echo $row['idq']?>" class="re_ans">Thay đổi</a>
    <?php }?>
</div><!--end wrap_ans-->
</div><!--end q_profile-->
<br />


<?php		
	}?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#66FF66" style="margin-left: 10px;
width: 98%;">
  <tr>
    <td align="center" valign="middle"><?php echo($p->getStart()+1).' - '.((($end=($p->getStart()+$p->getLimit()))>$count)?$count:$end).'/'.$count.' questions';?></td>
    <td align="center" valign="middle"><?php

        $page=$p->pageList($_GET["page"],$p->getPage());
		echo $page;
	?></td>
  </tr>
</table>
<?php
if($i==1){echo "You have no question answered";}
?>
</div>
